<?php
include_once "config/config.php";
include_once "lib/Arsip.php";
include_once "lib/Disposisi.php";
include_once "lib/Jabatan.php";
include_once "lib/Kewenangan_user.php";
include_once "lib/Log_user.php";
include_once "lib/Posisi_surat.php";
include_once "lib/Sifat.php";
include_once "lib/Surat_masuk.php";
include_once "lib/Tindaklanjut.php";
include_once "lib/Unit.php";
include_once "lib/User.php";
include_once "lib/Kewenangan.php";

include_once "lib/Surat_keluar.php";
include_once "lib/Jenis.php";
include_once "lib/Tujuan_surat.php";
include_once "lib/Kurir.php";
include_once "lib/Pengiriman_nonfisik.php";
include_once "lib/Kantor.php";
include_once "lib/Provinsi.php";



$config=new config();
$config->connect();

session_start();
if(!isset($_SESSION['nip']) && !isset($_SESSION['kewenangan']) && !isset($_SESSION['unit'])){

	header("Location:index.php");
}

$daftar_kewenangan_user = new Daftar_kewenangan_user();

if(isset($_POST['subheader'])){

	if(isset($_POST['unitx']) && $_POST['kewenanganx']== $_SESSION['kewenangan'] && ($_SESSION['kewenangan']=="pelaksana" || $_SESSION['kewenangan']=="kasubag/kasi" ||
		$_SESSION['kewenangan']=="kabu/kabid")){
		$_SESSION['unit']=$_POST['unitx'];
	//echo "1";
	} 

	if(isset($_POST['kewenanganx']) && $_POST['kewenanganx']!= $_SESSION['kewenangan']){
		$_SESSION['kewenangan'] = $_POST['kewenanganx'];
		$unit_kewenanganx = $daftar_kewenangan_user->getUnitKewenangan($_SESSION['nip'],$_SESSION['kewenangan']);
		$_SESSION['unit']= $unit_kewenanganx[0];
		//echo "2";
	} 

}


          
//echo $_SESSION['unit'];
//echo $_SESSION['kewenangan'];

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SIASKA</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" media="screen" href="css/style.css" />
<link rel="icon" type="image/png" href="images/xf-mail-icon.png">

<link type="text/css" href="jquery/css/jquery.ui.all.css" rel="stylesheet" />
<link type="text/css" href="jquery/css/jquery.ui.datepicker.css" rel="stylesheet" />
<script type="text/javascript" src="jquery/js/jquery-1.8.2.js"></script>
<script type="text/javascript" src="jquery/js/jquery.ui.core.js"></script>
<script type="text/javascript" src="jquery/js/jquery.ui.datepicker.js"></script>

</head>
<body>

<div id="header-wrapper">
	<div id="header">
		<div id="left">
		<img src="images/logo.png" width="500" height="125" alt="" />
		</div>
		
		<div id="right">
			<div id="top">
				<p id="jam" onload="jam()"></p>
			</div>
			
			<div id="bottom">
				<?php
				echo ucwords($_SESSION['nama']).", NIP.".ucwords($_SESSION['nip'])." <a href=\"logout.php\">(logout)</a>";
			?>
			</div>
		</div>
	</div>
	<div id="subheader">
	<?php
	
	$daftar_kewenangan_user = new Daftar_kewenangan_user();
	$kewenangan_usery = $daftar_kewenangan_user->getKewenanganByNip($_SESSION['nip']);
	$unit_kewenangany = $daftar_kewenangan_user->getUnitKewenangan($_SESSION['nip'],$_SESSION['kewenangan']);
	?>
	
	<form method=POST action="<?php echo $_SERVER['PHP_SELF']; ?>">
	<input type="hidden" name="subheader">
			Kewenangan: 
                    <select name="kewenanganx" onChange='this.form.submit()'>
                            <?php
                                    
									foreach ($kewenangan_usery as $r){
									
										if ($r == $_SESSION['kewenangan'])
                                            echo "<option value=".$r." selected>".ucwords($r)."</option>";
											
											else
                                            echo "<option value=".$r.">".ucwords($r)."</option>";
												
									}
                            ?>
                    </select>
					
			<?php
			if($_SESSION['kewenangan']=="pelaksana" || $_SESSION['kewenangan']=="kabu/kabid" || 
			$_SESSION['kewenangan']=="kasubag/kasi"){
			
				echo "&nbsp &nbsp Unit :";
				echo "<select name=\"unitx\" onChange=\"this.form.submit()\">";                  
									 
                    foreach ($unit_kewenangany as $r){
									 
					$daftar_unit = new Daftar_unit();
					$unitx = $daftar_unit->getById($r);										
						if ($_SESSION['unit'] == $r){
							echo "<option value=".$r." selected>".ucwords($unitx->getUnit())."</option>";
						} else {
							echo "<option value=".$r.">".ucwords($unitx->getUnit())."</option>";}                 										
						}
					   
                echo "</select>";
			} 
			
			?>
			
			
   </form>
	
	</div>
</div>
<script language="javascript"> 
function jam(){ 

	Hari = new Array("Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat","Sabtu");
	Bulan = new Array("Januari", "Februari", "Maret", "April", "Mei","Juni", "Juli","Agustus", "September", "Oktober", "November", "Desember");
	
	var waktu = new Date(); 
	var jam = waktu.getHours(); 
	var menit = waktu.getMinutes(); 
	var detik = waktu.getSeconds(); 
	var tahun = waktu.getFullYear();
	var bulan = Bulan[waktu.getMonth()];
	var tgl = waktu.getDate();
	var hari = Hari[waktu.getDay()]; 
	
	
	
	if (jam < 10){ jam = "0" + jam; } 
	if (menit < 10){ menit = "0" + menit; } 
	if (detik < 10){ detik = "0" + detik; } 
	var jam_div = document.getElementById('jam'); 
	jam_div.innerHTML = hari+", "+tgl+" "+bulan+" "+tahun+"  "+jam + ":" + menit + ":" + detik; setTimeout("jam()", 1000); } jam(); 
</script>